const wordLibrary = require("./wordLibrary.js");
// import wordLibrary from "./wordLibrary.mjs";
const bwKey = Array.from(new Set(Object.keys(wordLibrary)));
const getRandomKey = () => {
  console.log();
  return (Math.random() * bwKey.length) | 0;
};
// import readline from "readline";
const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
// d:详情，q:退出，b：返回（还会出现），回车（其他）：下一个
// bFlag:true:不删，false:删除
const pass = () => {
    !bFlag && bwKey.splice(key, 1);
    key = getRandomKey();
    if (!bwKey.length) {
        rl.close();
        return;
    }
    console.log(bwKey[key], bwKey.length);
};

let key = getRandomKey();
// 第一次输出单词
console.log(bwKey[key], bwKey.length);
// 控制单词是否从数组中删除
let bFlag = false
// 针对d计数
let n = 0
// 然后进入循环
rl.on("line", input => {
  const ref = {
    d:()=>{
      console.log(bwKey[key], ":", ...wordLibrary[bwKey[key]]);
      n = 0
    },
    b:()=>{
      pass();
    },
    q:()=>{
      process.exit(0);
    }
  }
  const ref_t = ref[input.trim()]
  if (ref_t) {
    bFlag = true
    ref_t()
  } else {
    !!n ? (bFlag = false) : n++
    pass();
  }
});
rl.on("close", () => {
  console.log("已经没有啦");
});